{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 第二章习题\n",
    "\n",
    "### 一、填空题\n",
    "\n",
    "1.列表的`sort()`方法没有返回值,或者说返回值为____none____."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2.已知列表 `data=[1,2,30 4]`，那么`data[2:100]`的值为_____[30,4]___."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[30, 4]"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data=[1,2,30,4]\n",
    "data[2:100]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3.己知`x=3`和`y=5`,那么执行语句`x,y=y,x`之后，`y`的值为___3_____."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "4．已知字典 `data= {'a;97, 'A' :65}`,那么`data.get('a', None)`的值为__97______."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 二、判断题\n",
    "\n",
    "1.生成器表达式的计算结果是一个元组。`(  false )`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2．包含列表的元组可以作为字典的“键”。`( false  )`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3．包含列表的元组不可以作为集合的元素。`(   ture )`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "4．列表的`rindex()`方法返回指定元素在列表中最后一次出现的位置。`(  ture  )`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 三、编程题\n",
    "\n",
    "1.输入一个字符串，输出其中每个字符的出现次数。要求使用标准库`collotections`中的`Counter`类,请自行查阅相关用法。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入字符串'123456'\n",
      "Counter({\"'\": 2, '1': 1, '2': 1, '3': 1, '4': 1, '5': 1, '6': 1})\n"
     ]
    }
   ],
   "source": [
    "from collections import Counter\n",
    "a = input(\"请输入字符串\")\n",
    "b = Counter(a)\n",
    "print(b)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2．输入一个字符串,输出其中只出现了一次的字符及其下标。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入一个字符串：'123'\n"
     ]
    }
   ],
   "source": [
    "text = input('请输入一个字符串：')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[('1', 1), ('2', 2), ('3', 3)]\n"
     ]
    }
   ],
   "source": [
    "positions = [(ch, index) for index, ch in enumerate(text) if text.index(ch)==text.rindex(ch)]\n",
    "print(positions)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3．输入一个字符串,输出其中每个唯一字符最后一次出现的下标。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入一个字符串：'123'\n"
     ]
    }
   ],
   "source": [
    "text = input('请输入一个字符串：')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[('1', 1), ('2', 2), ('3', 3), (\"'\", 4)]\n"
     ]
    }
   ],
   "source": [
    "positions =[(ch,index) for index,ch in enumerate(text)\n",
    "if index == text.rindex(ch)]\n",
    "print(positions)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "4．输入包含若干集合的列表，输出这些集合的并集。提示:使用`reduce()`函数和`operator`模块中的运算实现多个集合的并集。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入包含若干集合的列表：[{12,21},{32,23}]\n"
     ]
    }
   ],
   "source": [
    "from functools import reduce\n",
    "from operator import __or__\n",
    "x = eval(input('请输入包含若干集合的列表：'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{32, 12, 21, 23}\n"
     ]
    }
   ],
   "source": [
    "print(reduce(__or__,x))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "5．输入一个字符串,检查该字符串是否为回文（正着读和反看读都一样的字符串)，如果是就输出`Yes`，否则输出`No`。要求使用切片实现"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入一个字符串'123489'\n"
     ]
    }
   ],
   "source": [
    "s = eval(input('请输入一个字符串'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "No\n"
     ]
    }
   ],
   "source": [
    "x = s[::-1]\n",
    "if s == x:\n",
    "    print('Yes')\n",
    "else:\n",
    "    print('No')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 课本上65页课后习题"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1.可迭代对象\n",
    "2.4\n",
    "3.None\n",
    "4.remove()\n",
    "\n",
    "5.[6,7,9,11]\n",
    "\n",
    "6.() 键 值 键\n",
    "\n",
    "7.items() key() values()\n",
    "\n",
    "8.['dict(zip(a,b))']\n",
    "\n",
    "9.b=a[::3]\n",
    "\n",
    "10.5 for i in range(10)\n",
    "\n",
    "11.不可以"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['acdia']\n"
     ]
    }
   ],
   "source": [
    "data = ['acdia','aaccbbddee','okokok,yeyeye']\n",
    "print(list(filter(lambda s:len(set(s))/len(s) >0.5,data)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997]\n"
     ]
    }
   ],
   "source": [
    "def prime(x):                       \n",
    "    for i in range(2,x):\n",
    "        if x%i==0:\n",
    "            return False\n",
    "        if i==x-1:\n",
    "            return True\n",
    "output=filter(prime,range(2,1001))\n",
    "print(list(output))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[55, 15, 54, 22, 70, 92, 13, 75, 58, 95, 68, 23, 55, 88, 11, 13, 27, 9, 94, 89, 8, 99, 91, 99, 70, 16, 76, 59, 69, 2, 71, 47, 13, 84, 34, 80, 36, 38, 4, 80, 57, 3, 36, 10, 75, 26, 69, 41, 57, 22, 64, 86, 74, 100, 98, 93, 97, 22, 55, 96, 36, 14, 71, 1, 4, 4, 34, 86, 74, 43, 44, 70, 30, 66, 66, 55, 5, 57, 71, 62, 66, 65, 6, 87, 6, 15, 65, 50, 13, 21, 17, 27, 4, 51, 39, 53, 86, 69, 81, 18, 14, 71, 52, 76, 24, 43, 13, 50, 96, 38, 4, 32, 44, 43, 0, 66, 12, 26, 49, 34, 61, 76, 6, 92, 93, 39, 51, 24, 59, 44, 40, 53, 81, 8, 12, 25, 55, 18, 81, 64, 68, 54, 54, 83, 20, 8, 46, 13, 16, 79, 59, 66, 6, 70, 69, 83, 46, 82, 9, 54, 39, 30, 78, 40, 80, 34, 38, 72, 51, 58, 31, 9, 47, 89, 16, 76, 92, 41, 44, 43, 96, 6, 69, 8, 50, 49, 15, 6, 78, 87, 39, 20, 53, 55, 51, 36, 3, 75, 51, 83, 39, 56, 9, 26, 16, 81, 28, 82, 22, 99, 17, 2, 29, 25, 47, 90, 78, 88, 83, 75, 50, 81, 75, 4, 44, 76, 7, 76, 13, 48, 92, 66, 41, 11, 33, 64, 24, 0, 84, 98, 28, 50, 31, 63, 52, 16, 31, 20, 85, 62, 64, 89, 60, 32, 9, 55, 16, 63, 44, 91, 44, 51, 9, 69, 23, 42, 8, 81, 84, 28, 8, 90, 68, 97, 28, 58, 64, 77, 74, 76, 38, 68, 28, 53, 15, 44, 59, 11, 57, 11, 86, 51, 5, 1, 12, 63, 50, 60, 98, 17, 32, 95, 19, 45, 9, 85, 82, 61, 55, 74, 20, 61, 16, 50, 46, 23, 3, 30, 50, 88, 68, 91, 87, 61, 25, 13, 59, 28, 12, 17, 37, 29, 40, 72, 46, 60, 30, 48, 95, 72, 39, 29, 5, 83, 44, 62, 58, 16, 66, 1, 38, 17, 98, 32, 36, 11, 68, 2, 6, 70, 50, 22, 70, 3, 9, 17, 65, 22, 96, 99, 94, 58, 24, 60, 26, 37, 24, 79, 53, 62, 73, 33, 90, 21, 34, 88, 76, 41, 100, 43, 93, 26, 60, 18, 33, 70, 82, 66, 31, 93, 63, 91, 57, 48, 27, 89, 81, 50, 22, 98, 58, 36, 94, 64, 54, 82, 37, 62, 52, 23, 41, 66, 86, 56, 51, 67, 87, 81, 2, 6, 19, 18, 64, 35, 28, 6, 9, 10, 100, 93, 16, 80, 100, 59, 48, 5, 63, 41, 69, 76, 37, 60, 34, 61, 92, 94, 66, 99, 5, 16, 75, 51, 56, 96, 42, 69, 80, 14, 81, 4, 13, 10, 22, 31, 53, 62, 61, 21, 5, 57, 23, 58, 42, 2, 96, 12, 12, 89, 43, 49, 86, 1, 83, 57, 10, 86, 49, 45, 90, 17, 73, 5, 59, 85, 63, 18, 56, 75, 4, 48, 61, 9, 86, 41, 42, 72, 66, 62, 81, 90, 11, 12, 54, 0, 43, 80, 79, 97, 38, 40, 88, 29, 54, 71, 18, 94, 8, 94, 19, 42, 4, 74, 49, 65, 23, 38, 19, 76, 37, 50, 13, 17, 75, 42, 65, 89, 25, 18, 52, 62, 35, 13, 5, 95, 37, 86, 1, 36, 2, 12, 17, 35, 50, 99, 16, 62, 83, 27, 48, 93, 36, 88, 86, 24, 41, 49, 22, 24, 97, 69, 43, 61, 40, 56, 63, 61, 31, 49, 60, 24, 75, 94, 10, 43, 17, 29, 35, 54, 8, 5, 16, 32, 90, 33, 35, 75, 62, 86, 67, 83, 88, 36, 52, 61, 4, 71, 59, 31, 69, 50, 70, 37, 51, 95, 85, 85, 44, 28, 37, 41, 48, 10, 51, 47, 23, 84, 85, 87, 84, 7, 61, 43, 100, 2, 54, 92, 75, 63, 18, 35, 47, 85, 94, 55, 70, 6, 25, 37, 91, 34, 2, 40, 2, 92, 60, 51, 64, 9, 19, 74, 43, 7, 35, 66, 8, 36, 17, 86, 75, 54, 47, 85, 26, 33, 60, 3, 67, 37, 15, 71, 71, 72, 72, 4, 69, 67, 81, 29, 28, 58, 51, 97, 79, 37, 68, 26, 47, 25, 46, 94, 25, 56, 50, 58, 80, 68, 19, 55, 22, 66, 31, 7, 41, 39, 86, 37, 70, 85, 60, 16, 39, 27, 66, 44, 13, 69, 18, 49, 29, 7, 92, 22, 54, 35, 23, 2, 6, 31, 89, 85, 36, 55, 93, 58, 52, 31, 64, 40, 15, 54, 62, 47, 65, 18, 24, 90, 22, 79, 53, 71, 54, 89, 40, 28, 16, 9, 38, 79, 32, 10, 92, 66, 41, 45, 82, 17, 75, 34, 57, 18, 4, 67, 89, 42, 69, 32, 54, 43, 48, 17, 20, 41, 95, 0, 90, 12, 25, 6, 54, 61, 63, 75, 66, 26, 57, 1, 24, 70, 39, 80, 96, 85, 24, 80, 26, 41, 27, 92, 57, 56, 39, 27, 40, 46, 29, 50, 25, 10, 96, 1, 9, 42, 40, 99, 17, 38, 43, 88, 38, 61, 10, 67, 54, 23, 63, 88, 5, 31, 91, 49, 26, 85, 15, 41, 18, 5, 89, 72, 9, 98, 45, 76, 59, 43, 1, 83, 5, 85, 99, 48, 25, 10, 98, 50, 81, 50, 12, 72, 97, 12, 72, 40, 13, 97, 76, 59, 69, 43, 41, 77, 21, 18, 36, 2, 26, 17, 96, 87, 43, 45, 31, 69, 72, 77, 72, 51, 74, 56, 89, 12, 4, 4, 12, 55, 94, 63, 39, 8, 43, 36, 7, 43, 45, 92, 25, 33, 47, 98, 75, 79, 2, 15, 99, 1, 18, 1, 7, 52, 92, 90, 29, 4, 31, 20, 48, 82, 54, 26, 4, 87, 14, 83, 11, 69, 78, 49, 13, 87, 6, 62, 33, 32, 67, 44, 92, 14, 89, 95, 73, 50, 23, 88, 63, 12, 44, 55, 65, 4, 78, 30]\n",
      "55 : 13\n",
      "15 : 8\n",
      "54 : 17\n",
      "22 : 12\n",
      "70 : 11\n",
      "92 : 13\n",
      "13 : 14\n",
      "75 : 15\n",
      "58 : 10\n",
      "95 : 7\n",
      "68 : 8\n",
      "23 : 10\n",
      "55 : 13\n",
      "88 : 10\n",
      "11 : 7\n",
      "13 : 14\n",
      "27 : 7\n",
      "9 : 14\n",
      "94 : 10\n",
      "89 : 12\n",
      "8 : 10\n",
      "99 : 9\n",
      "91 : 6\n",
      "99 : 9\n",
      "70 : 11\n",
      "16 : 14\n",
      "76 : 12\n",
      "59 : 10\n",
      "69 : 16\n",
      "2 : 12\n",
      "71 : 9\n",
      "47 : 9\n",
      "13 : 14\n",
      "84 : 5\n",
      "34 : 8\n",
      "80 : 9\n",
      "36 : 13\n",
      "38 : 10\n",
      "4 : 17\n",
      "80 : 9\n",
      "57 : 10\n",
      "3 : 5\n",
      "36 : 13\n",
      "10 : 10\n",
      "75 : 15\n",
      "26 : 12\n",
      "69 : 16\n",
      "41 : 15\n",
      "57 : 10\n",
      "22 : 12\n",
      "64 : 9\n",
      "86 : 13\n",
      "74 : 7\n",
      "100 : 5\n",
      "98 : 8\n",
      "93 : 7\n",
      "97 : 7\n",
      "22 : 12\n",
      "55 : 13\n",
      "96 : 9\n",
      "36 : 13\n",
      "14 : 5\n",
      "71 : 9\n",
      "1 : 10\n",
      "4 : 17\n",
      "4 : 17\n",
      "34 : 8\n",
      "86 : 13\n",
      "74 : 7\n",
      "43 : 18\n",
      "44 : 13\n",
      "70 : 11\n",
      "30 : 5\n",
      "66 : 16\n",
      "66 : 16\n",
      "55 : 13\n",
      "5 : 12\n",
      "57 : 10\n",
      "71 : 9\n",
      "62 : 12\n",
      "66 : 16\n",
      "65 : 7\n",
      "6 : 13\n",
      "87 : 8\n",
      "6 : 13\n",
      "15 : 8\n",
      "65 : 7\n",
      "50 : 18\n",
      "13 : 14\n",
      "21 : 4\n",
      "17 : 15\n",
      "27 : 7\n",
      "4 : 17\n",
      "51 : 14\n",
      "39 : 11\n",
      "53 : 7\n",
      "86 : 13\n",
      "69 : 16\n",
      "81 : 12\n",
      "18 : 14\n",
      "14 : 5\n",
      "71 : 9\n",
      "52 : 7\n",
      "76 : 12\n",
      "24 : 11\n",
      "43 : 18\n",
      "13 : 14\n",
      "50 : 18\n",
      "96 : 9\n",
      "38 : 10\n",
      "4 : 17\n",
      "32 : 8\n",
      "44 : 13\n",
      "43 : 18\n",
      "0 : 4\n",
      "66 : 16\n",
      "12 : 14\n",
      "26 : 12\n",
      "49 : 10\n",
      "34 : 8\n",
      "61 : 13\n",
      "76 : 12\n",
      "6 : 13\n",
      "92 : 13\n",
      "93 : 7\n",
      "39 : 11\n",
      "51 : 14\n",
      "24 : 11\n",
      "59 : 10\n",
      "44 : 13\n",
      "40 : 11\n",
      "53 : 7\n",
      "81 : 12\n",
      "8 : 10\n",
      "12 : 14\n",
      "25 : 11\n",
      "55 : 13\n",
      "18 : 14\n",
      "81 : 12\n",
      "64 : 9\n",
      "68 : 8\n",
      "54 : 17\n",
      "54 : 17\n",
      "83 : 10\n",
      "20 : 6\n",
      "8 : 10\n",
      "46 : 6\n",
      "13 : 14\n",
      "16 : 14\n",
      "79 : 7\n",
      "59 : 10\n",
      "66 : 16\n",
      "6 : 13\n",
      "70 : 11\n",
      "69 : 16\n",
      "83 : 10\n",
      "46 : 6\n",
      "82 : 7\n",
      "9 : 14\n",
      "54 : 17\n",
      "39 : 11\n",
      "30 : 5\n",
      "78 : 5\n",
      "40 : 11\n",
      "80 : 9\n",
      "34 : 8\n",
      "38 : 10\n",
      "72 : 11\n",
      "51 : 14\n",
      "58 : 10\n",
      "31 : 13\n",
      "9 : 14\n",
      "47 : 9\n",
      "89 : 12\n",
      "16 : 14\n",
      "76 : 12\n",
      "92 : 13\n",
      "41 : 15\n",
      "44 : 13\n",
      "43 : 18\n",
      "96 : 9\n",
      "6 : 13\n",
      "69 : 16\n",
      "8 : 10\n",
      "50 : 18\n",
      "49 : 10\n",
      "15 : 8\n",
      "6 : 13\n",
      "78 : 5\n",
      "87 : 8\n",
      "39 : 11\n",
      "20 : 6\n",
      "53 : 7\n",
      "55 : 13\n",
      "51 : 14\n",
      "36 : 13\n",
      "3 : 5\n",
      "75 : 15\n",
      "51 : 14\n",
      "83 : 10\n",
      "39 : 11\n",
      "56 : 8\n",
      "9 : 14\n",
      "26 : 12\n",
      "16 : 14\n",
      "81 : 12\n",
      "28 : 10\n",
      "82 : 7\n",
      "22 : 12\n",
      "99 : 9\n",
      "17 : 15\n",
      "2 : 12\n",
      "29 : 9\n",
      "25 : 11\n",
      "47 : 9\n",
      "90 : 9\n",
      "78 : 5\n",
      "88 : 10\n",
      "83 : 10\n",
      "75 : 15\n",
      "50 : 18\n",
      "81 : 12\n",
      "75 : 15\n",
      "4 : 17\n",
      "44 : 13\n",
      "76 : 12\n",
      "7 : 7\n",
      "76 : 12\n",
      "13 : 14\n",
      "48 : 10\n",
      "92 : 13\n",
      "66 : 16\n",
      "41 : 15\n",
      "11 : 7\n",
      "33 : 7\n",
      "64 : 9\n",
      "24 : 11\n",
      "0 : 4\n",
      "84 : 5\n",
      "98 : 8\n",
      "28 : 10\n",
      "50 : 18\n",
      "31 : 13\n",
      "63 : 12\n",
      "52 : 7\n",
      "16 : 14\n",
      "31 : 13\n",
      "20 : 6\n",
      "85 : 13\n",
      "62 : 12\n",
      "64 : 9\n",
      "89 : 12\n",
      "60 : 10\n",
      "32 : 8\n",
      "9 : 14\n",
      "55 : 13\n",
      "16 : 14\n",
      "63 : 12\n",
      "44 : 13\n",
      "91 : 6\n",
      "44 : 13\n",
      "51 : 14\n",
      "9 : 14\n",
      "69 : 16\n",
      "23 : 10\n",
      "42 : 8\n",
      "8 : 10\n",
      "81 : 12\n",
      "84 : 5\n",
      "28 : 10\n",
      "8 : 10\n",
      "90 : 9\n",
      "68 : 8\n",
      "97 : 7\n",
      "28 : 10\n",
      "58 : 10\n",
      "64 : 9\n",
      "77 : 3\n",
      "74 : 7\n",
      "76 : 12\n",
      "38 : 10\n",
      "68 : 8\n",
      "28 : 10\n",
      "53 : 7\n",
      "15 : 8\n",
      "44 : 13\n",
      "59 : 10\n",
      "11 : 7\n",
      "57 : 10\n",
      "11 : 7\n",
      "86 : 13\n",
      "51 : 14\n",
      "5 : 12\n",
      "1 : 10\n",
      "12 : 14\n",
      "63 : 12\n",
      "50 : 18\n",
      "60 : 10\n",
      "98 : 8\n",
      "17 : 15\n",
      "32 : 8\n",
      "95 : 7\n",
      "19 : 6\n",
      "45 : 6\n",
      "9 : 14\n",
      "85 : 13\n",
      "82 : 7\n",
      "61 : 13\n",
      "55 : 13\n",
      "74 : 7\n",
      "20 : 6\n",
      "61 : 13\n",
      "16 : 14\n",
      "50 : 18\n",
      "46 : 6\n",
      "23 : 10\n",
      "3 : 5\n",
      "30 : 5\n",
      "50 : 18\n",
      "88 : 10\n",
      "68 : 8\n",
      "91 : 6\n",
      "87 : 8\n",
      "61 : 13\n",
      "25 : 11\n",
      "13 : 14\n",
      "59 : 10\n",
      "28 : 10\n",
      "12 : 14\n",
      "17 : 15\n",
      "37 : 12\n",
      "29 : 9\n",
      "40 : 11\n",
      "72 : 11\n",
      "46 : 6\n",
      "60 : 10\n",
      "30 : 5\n",
      "48 : 10\n",
      "95 : 7\n",
      "72 : 11\n",
      "39 : 11\n",
      "29 : 9\n",
      "5 : 12\n",
      "83 : 10\n",
      "44 : 13\n",
      "62 : 12\n",
      "58 : 10\n",
      "16 : 14\n",
      "66 : 16\n",
      "1 : 10\n",
      "38 : 10\n",
      "17 : 15\n",
      "98 : 8\n",
      "32 : 8\n",
      "36 : 13\n",
      "11 : 7\n",
      "68 : 8\n",
      "2 : 12\n",
      "6 : 13\n",
      "70 : 11\n",
      "50 : 18\n",
      "22 : 12\n",
      "70 : 11\n",
      "3 : 5\n",
      "9 : 14\n",
      "17 : 15\n",
      "65 : 7\n",
      "22 : 12\n",
      "96 : 9\n",
      "99 : 9\n",
      "94 : 10\n",
      "58 : 10\n",
      "24 : 11\n",
      "60 : 10\n",
      "26 : 12\n",
      "37 : 12\n",
      "24 : 11\n",
      "79 : 7\n",
      "53 : 7\n",
      "62 : 12\n",
      "73 : 3\n",
      "33 : 7\n",
      "90 : 9\n",
      "21 : 4\n",
      "34 : 8\n",
      "88 : 10\n",
      "76 : 12\n",
      "41 : 15\n",
      "100 : 5\n",
      "43 : 18\n",
      "93 : 7\n",
      "26 : 12\n",
      "60 : 10\n",
      "18 : 14\n",
      "33 : 7\n",
      "70 : 11\n",
      "82 : 7\n",
      "66 : 16\n",
      "31 : 13\n",
      "93 : 7\n",
      "63 : 12\n",
      "91 : 6\n",
      "57 : 10\n",
      "48 : 10\n",
      "27 : 7\n",
      "89 : 12\n",
      "81 : 12\n",
      "50 : 18\n",
      "22 : 12\n",
      "98 : 8\n",
      "58 : 10\n",
      "36 : 13\n",
      "94 : 10\n",
      "64 : 9\n",
      "54 : 17\n",
      "82 : 7\n",
      "37 : 12\n",
      "62 : 12\n",
      "52 : 7\n",
      "23 : 10\n",
      "41 : 15\n",
      "66 : 16\n",
      "86 : 13\n",
      "56 : 8\n",
      "51 : 14\n",
      "67 : 7\n",
      "87 : 8\n",
      "81 : 12\n",
      "2 : 12\n",
      "6 : 13\n",
      "19 : 6\n",
      "18 : 14\n",
      "64 : 9\n",
      "35 : 8\n",
      "28 : 10\n",
      "6 : 13\n",
      "9 : 14\n",
      "10 : 10\n",
      "100 : 5\n",
      "93 : 7\n",
      "16 : 14\n",
      "80 : 9\n",
      "100 : 5\n",
      "59 : 10\n",
      "48 : 10\n",
      "5 : 12\n",
      "63 : 12\n",
      "41 : 15\n",
      "69 : 16\n",
      "76 : 12\n",
      "37 : 12\n",
      "60 : 10\n",
      "34 : 8\n",
      "61 : 13\n",
      "92 : 13\n",
      "94 : 10\n",
      "66 : 16\n",
      "99 : 9\n",
      "5 : 12\n",
      "16 : 14\n",
      "75 : 15\n",
      "51 : 14\n",
      "56 : 8\n",
      "96 : 9\n",
      "42 : 8\n",
      "69 : 16\n",
      "80 : 9\n",
      "14 : 5\n",
      "81 : 12\n",
      "4 : 17\n",
      "13 : 14\n",
      "10 : 10\n",
      "22 : 12\n",
      "31 : 13\n",
      "53 : 7\n",
      "62 : 12\n",
      "61 : 13\n",
      "21 : 4\n",
      "5 : 12\n",
      "57 : 10\n",
      "23 : 10\n",
      "58 : 10\n",
      "42 : 8\n",
      "2 : 12\n",
      "96 : 9\n",
      "12 : 14\n",
      "12 : 14\n",
      "89 : 12\n",
      "43 : 18\n",
      "49 : 10\n",
      "86 : 13\n",
      "1 : 10\n",
      "83 : 10\n",
      "57 : 10\n",
      "10 : 10\n",
      "86 : 13\n",
      "49 : 10\n",
      "45 : 6\n",
      "90 : 9\n",
      "17 : 15\n",
      "73 : 3\n",
      "5 : 12\n",
      "59 : 10\n",
      "85 : 13\n",
      "63 : 12\n",
      "18 : 14\n",
      "56 : 8\n",
      "75 : 15\n",
      "4 : 17\n",
      "48 : 10\n",
      "61 : 13\n",
      "9 : 14\n",
      "86 : 13\n",
      "41 : 15\n",
      "42 : 8\n",
      "72 : 11\n",
      "66 : 16\n",
      "62 : 12\n",
      "81 : 12\n",
      "90 : 9\n",
      "11 : 7\n",
      "12 : 14\n",
      "54 : 17\n",
      "0 : 4\n",
      "43 : 18\n",
      "80 : 9\n",
      "79 : 7\n",
      "97 : 7\n",
      "38 : 10\n",
      "40 : 11\n",
      "88 : 10\n",
      "29 : 9\n",
      "54 : 17\n",
      "71 : 9\n",
      "18 : 14\n",
      "94 : 10\n",
      "8 : 10\n",
      "94 : 10\n",
      "19 : 6\n",
      "42 : 8\n",
      "4 : 17\n",
      "74 : 7\n",
      "49 : 10\n",
      "65 : 7\n",
      "23 : 10\n",
      "38 : 10\n",
      "19 : 6\n",
      "76 : 12\n",
      "37 : 12\n",
      "50 : 18\n",
      "13 : 14\n",
      "17 : 15\n",
      "75 : 15\n",
      "42 : 8\n",
      "65 : 7\n",
      "89 : 12\n",
      "25 : 11\n",
      "18 : 14\n",
      "52 : 7\n",
      "62 : 12\n",
      "35 : 8\n",
      "13 : 14\n",
      "5 : 12\n",
      "95 : 7\n",
      "37 : 12\n",
      "86 : 13\n",
      "1 : 10\n",
      "36 : 13\n",
      "2 : 12\n",
      "12 : 14\n",
      "17 : 15\n",
      "35 : 8\n",
      "50 : 18\n",
      "99 : 9\n",
      "16 : 14\n",
      "62 : 12\n",
      "83 : 10\n",
      "27 : 7\n",
      "48 : 10\n",
      "93 : 7\n",
      "36 : 13\n",
      "88 : 10\n",
      "86 : 13\n",
      "24 : 11\n",
      "41 : 15\n",
      "49 : 10\n",
      "22 : 12\n",
      "24 : 11\n",
      "97 : 7\n",
      "69 : 16\n",
      "43 : 18\n",
      "61 : 13\n",
      "40 : 11\n",
      "56 : 8\n",
      "63 : 12\n",
      "61 : 13\n",
      "31 : 13\n",
      "49 : 10\n",
      "60 : 10\n",
      "24 : 11\n",
      "75 : 15\n",
      "94 : 10\n",
      "10 : 10\n",
      "43 : 18\n",
      "17 : 15\n",
      "29 : 9\n",
      "35 : 8\n",
      "54 : 17\n",
      "8 : 10\n",
      "5 : 12\n",
      "16 : 14\n",
      "32 : 8\n",
      "90 : 9\n",
      "33 : 7\n",
      "35 : 8\n",
      "75 : 15\n",
      "62 : 12\n",
      "86 : 13\n",
      "67 : 7\n",
      "83 : 10\n",
      "88 : 10\n",
      "36 : 13\n",
      "52 : 7\n",
      "61 : 13\n",
      "4 : 17\n",
      "71 : 9\n",
      "59 : 10\n",
      "31 : 13\n",
      "69 : 16\n",
      "50 : 18\n",
      "70 : 11\n",
      "37 : 12\n",
      "51 : 14\n",
      "95 : 7\n",
      "85 : 13\n",
      "85 : 13\n",
      "44 : 13\n",
      "28 : 10\n",
      "37 : 12\n",
      "41 : 15\n",
      "48 : 10\n",
      "10 : 10\n",
      "51 : 14\n",
      "47 : 9\n",
      "23 : 10\n",
      "84 : 5\n",
      "85 : 13\n",
      "87 : 8\n",
      "84 : 5\n",
      "7 : 7\n",
      "61 : 13\n",
      "43 : 18\n",
      "100 : 5\n",
      "2 : 12\n",
      "54 : 17\n",
      "92 : 13\n",
      "75 : 15\n",
      "63 : 12\n",
      "18 : 14\n",
      "35 : 8\n",
      "47 : 9\n",
      "85 : 13\n",
      "94 : 10\n",
      "55 : 13\n",
      "70 : 11\n",
      "6 : 13\n",
      "25 : 11\n",
      "37 : 12\n",
      "91 : 6\n",
      "34 : 8\n",
      "2 : 12\n",
      "40 : 11\n",
      "2 : 12\n",
      "92 : 13\n",
      "60 : 10\n",
      "51 : 14\n",
      "64 : 9\n",
      "9 : 14\n",
      "19 : 6\n",
      "74 : 7\n",
      "43 : 18\n",
      "7 : 7\n",
      "35 : 8\n",
      "66 : 16\n",
      "8 : 10\n",
      "36 : 13\n",
      "17 : 15\n",
      "86 : 13\n",
      "75 : 15\n",
      "54 : 17\n",
      "47 : 9\n",
      "85 : 13\n",
      "26 : 12\n",
      "33 : 7\n",
      "60 : 10\n",
      "3 : 5\n",
      "67 : 7\n",
      "37 : 12\n",
      "15 : 8\n",
      "71 : 9\n",
      "71 : 9\n",
      "72 : 11\n",
      "72 : 11\n",
      "4 : 17\n",
      "69 : 16\n",
      "67 : 7\n",
      "81 : 12\n",
      "29 : 9\n",
      "28 : 10\n",
      "58 : 10\n",
      "51 : 14\n",
      "97 : 7\n",
      "79 : 7\n",
      "37 : 12\n",
      "68 : 8\n",
      "26 : 12\n",
      "47 : 9\n",
      "25 : 11\n",
      "46 : 6\n",
      "94 : 10\n",
      "25 : 11\n",
      "56 : 8\n",
      "50 : 18\n",
      "58 : 10\n",
      "80 : 9\n",
      "68 : 8\n",
      "19 : 6\n",
      "55 : 13\n",
      "22 : 12\n",
      "66 : 16\n",
      "31 : 13\n",
      "7 : 7\n",
      "41 : 15\n",
      "39 : 11\n",
      "86 : 13\n",
      "37 : 12\n",
      "70 : 11\n",
      "85 : 13\n",
      "60 : 10\n",
      "16 : 14\n",
      "39 : 11\n",
      "27 : 7\n",
      "66 : 16\n",
      "44 : 13\n",
      "13 : 14\n",
      "69 : 16\n",
      "18 : 14\n",
      "49 : 10\n",
      "29 : 9\n",
      "7 : 7\n",
      "92 : 13\n",
      "22 : 12\n",
      "54 : 17\n",
      "35 : 8\n",
      "23 : 10\n",
      "2 : 12\n",
      "6 : 13\n",
      "31 : 13\n",
      "89 : 12\n",
      "85 : 13\n",
      "36 : 13\n",
      "55 : 13\n",
      "93 : 7\n",
      "58 : 10\n",
      "52 : 7\n",
      "31 : 13\n",
      "64 : 9\n",
      "40 : 11\n",
      "15 : 8\n",
      "54 : 17\n",
      "62 : 12\n",
      "47 : 9\n",
      "65 : 7\n",
      "18 : 14\n",
      "24 : 11\n",
      "90 : 9\n",
      "22 : 12\n",
      "79 : 7\n",
      "53 : 7\n",
      "71 : 9\n",
      "54 : 17\n",
      "89 : 12\n",
      "40 : 11\n",
      "28 : 10\n",
      "16 : 14\n",
      "9 : 14\n",
      "38 : 10\n",
      "79 : 7\n",
      "32 : 8\n",
      "10 : 10\n",
      "92 : 13\n",
      "66 : 16\n",
      "41 : 15\n",
      "45 : 6\n",
      "82 : 7\n",
      "17 : 15\n",
      "75 : 15\n",
      "34 : 8\n",
      "57 : 10\n",
      "18 : 14\n",
      "4 : 17\n",
      "67 : 7\n",
      "89 : 12\n",
      "42 : 8\n",
      "69 : 16\n",
      "32 : 8\n",
      "54 : 17\n",
      "43 : 18\n",
      "48 : 10\n",
      "17 : 15\n",
      "20 : 6\n",
      "41 : 15\n",
      "95 : 7\n",
      "0 : 4\n",
      "90 : 9\n",
      "12 : 14\n",
      "25 : 11\n",
      "6 : 13\n",
      "54 : 17\n",
      "61 : 13\n",
      "63 : 12\n",
      "75 : 15\n",
      "66 : 16\n",
      "26 : 12\n",
      "57 : 10\n",
      "1 : 10\n",
      "24 : 11\n",
      "70 : 11\n",
      "39 : 11\n",
      "80 : 9\n",
      "96 : 9\n",
      "85 : 13\n",
      "24 : 11\n",
      "80 : 9\n",
      "26 : 12\n",
      "41 : 15\n",
      "27 : 7\n",
      "92 : 13\n",
      "57 : 10\n",
      "56 : 8\n",
      "39 : 11\n",
      "27 : 7\n",
      "40 : 11\n",
      "46 : 6\n",
      "29 : 9\n",
      "50 : 18\n",
      "25 : 11\n",
      "10 : 10\n",
      "96 : 9\n",
      "1 : 10\n",
      "9 : 14\n",
      "42 : 8\n",
      "40 : 11\n",
      "99 : 9\n",
      "17 : 15\n",
      "38 : 10\n",
      "43 : 18\n",
      "88 : 10\n",
      "38 : 10\n",
      "61 : 13\n",
      "10 : 10\n",
      "67 : 7\n",
      "54 : 17\n",
      "23 : 10\n",
      "63 : 12\n",
      "88 : 10\n",
      "5 : 12\n",
      "31 : 13\n",
      "91 : 6\n",
      "49 : 10\n",
      "26 : 12\n",
      "85 : 13\n",
      "15 : 8\n",
      "41 : 15\n",
      "18 : 14\n",
      "5 : 12\n",
      "89 : 12\n",
      "72 : 11\n",
      "9 : 14\n",
      "98 : 8\n",
      "45 : 6\n",
      "76 : 12\n",
      "59 : 10\n",
      "43 : 18\n",
      "1 : 10\n",
      "83 : 10\n",
      "5 : 12\n",
      "85 : 13\n",
      "99 : 9\n",
      "48 : 10\n",
      "25 : 11\n",
      "10 : 10\n",
      "98 : 8\n",
      "50 : 18\n",
      "81 : 12\n",
      "50 : 18\n",
      "12 : 14\n",
      "72 : 11\n",
      "97 : 7\n",
      "12 : 14\n",
      "72 : 11\n",
      "40 : 11\n",
      "13 : 14\n",
      "97 : 7\n",
      "76 : 12\n",
      "59 : 10\n",
      "69 : 16\n",
      "43 : 18\n",
      "41 : 15\n",
      "77 : 3\n",
      "21 : 4\n",
      "18 : 14\n",
      "36 : 13\n",
      "2 : 12\n",
      "26 : 12\n",
      "17 : 15\n",
      "96 : 9\n",
      "87 : 8\n",
      "43 : 18\n",
      "45 : 6\n",
      "31 : 13\n",
      "69 : 16\n",
      "72 : 11\n",
      "77 : 3\n",
      "72 : 11\n",
      "51 : 14\n",
      "74 : 7\n",
      "56 : 8\n",
      "89 : 12\n",
      "12 : 14\n",
      "4 : 17\n",
      "4 : 17\n",
      "12 : 14\n",
      "55 : 13\n",
      "94 : 10\n",
      "63 : 12\n",
      "39 : 11\n",
      "8 : 10\n",
      "43 : 18\n",
      "36 : 13\n",
      "7 : 7\n",
      "43 : 18\n",
      "45 : 6\n",
      "92 : 13\n",
      "25 : 11\n",
      "33 : 7\n",
      "47 : 9\n",
      "98 : 8\n",
      "75 : 15\n",
      "79 : 7\n",
      "2 : 12\n",
      "15 : 8\n",
      "99 : 9\n",
      "1 : 10\n",
      "18 : 14\n",
      "1 : 10\n",
      "7 : 7\n",
      "52 : 7\n",
      "92 : 13\n",
      "90 : 9\n",
      "29 : 9\n",
      "4 : 17\n",
      "31 : 13\n",
      "20 : 6\n",
      "48 : 10\n",
      "82 : 7\n",
      "54 : 17\n",
      "26 : 12\n",
      "4 : 17\n",
      "87 : 8\n",
      "14 : 5\n",
      "83 : 10\n",
      "11 : 7\n",
      "69 : 16\n",
      "78 : 5\n",
      "49 : 10\n",
      "13 : 14\n",
      "87 : 8\n",
      "6 : 13\n",
      "62 : 12\n",
      "33 : 7\n",
      "32 : 8\n",
      "67 : 7\n",
      "44 : 13\n",
      "92 : 13\n",
      "14 : 5\n",
      "89 : 12\n",
      "95 : 7\n",
      "73 : 3\n",
      "50 : 18\n",
      "23 : 10\n",
      "88 : 10\n",
      "63 : 12\n",
      "12 : 14\n",
      "44 : 13\n",
      "55 : 13\n",
      "65 : 7\n",
      "4 : 17\n",
      "78 : 5\n",
      "30 : 5\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "x = [random.randint(0,100)for i in range(1000)]\n",
    "print(x)\n",
    "for i in x:\n",
    "    print(i,':',x.count(i))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "input your nameWEN\n"
     ]
    }
   ],
   "source": [
    "d = {'WEN':'1','LI':'2','CHUAN':3}\n",
    "a = input('input your name')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "您输入的键不存在\n"
     ]
    }
   ],
   "source": [
    "print(d.get(a,'您输入的键不存在'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[30, 56, 98, 92, 69, 79, 5, 57, 96, 72, 0, 7, 95, 26, 69, 56, 70, 14, 70, 74]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import random\n",
    "s = [random.randint(0,100)for i in range(20)]\n",
    "s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[5, 30, 56, 57, 69, 72, 79, 92, 96, 98, 95, 74, 70, 70, 69, 56, 26, 14, 7, 0]\n"
     ]
    }
   ],
   "source": [
    "a = sorted(s[:10])\n",
    "b = sorted(s[10:],reverse = True)\n",
    "x = a+b\n",
    "print(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": false,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {
    "height": "calc(100% - 180px)",
    "left": "10px",
    "top": "150px",
    "width": "165px"
   },
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
